$().ready(function () {
	validateRule();
	formatDate();

	window.productCallback = function (data) {
		console.log(data);

		$("#productId").val(data.productId);
		$("#productName").val(data.productName);
		layer.close(productIndex);
	};
});

$.validator.setDefaults({
	submitHandler: function () {
		save();
	}
});

function save() {
	var formData = new FormData($("#signupForm")[0]);
	$.ajax({
		type: "POST",
		url: getProjectName()+"/stock/update",
		data: formData,// 你的formid
		async: false,
		cache: false,
		contentType: false,
		processData: false,
		error: function (request) {
			parent.layer.alert("Connection error");
		},
		success: function (data) {
			if (data.code == 0) {
				parent.layer.msg(data.msg);
				parent.location.reload();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}

var productIndex;

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules: {
			name: {
				required: true
			}
		},
		messages: {
			name: {
				required: icon + "请输入姓名"
			}
		}
	})
}

/**
 *
 */
function productSelect() {
	productIndex = layer.open({
		type: 2,
		title: '选择产品',
		maxmin: false,
		shadeClose: false, // 点击遮罩关闭层
		area: ['100%', '100%'],
		content: getProjectName()+'/invoice/view/product/select' // iframe的url
	});
}